import request from '../utils/request'

// 获取用户可访问的仪表板列表
export function getDashboardList() {
  // 从当前登录用户信息中获取用户ID
  const userId = JSON.parse(localStorage.getItem('userInfo')).id
  return request({
    url: '/api/dashboard-permission/list',
    method: 'get',
    params: { userId }
  })
}

// 获取仪表板详情
export function getDashboardInfo(id) {
  return request({
    url: `/api/dashboard-permission/${id}`,
    method: 'get'
  })
}

// 获取访问者列表
export function getVisitors(dashboardId) {
  return request({
    url: `/api/dashboard-permission/${dashboardId}/visitors`,
    method: 'get'
  })
}

// 添加访问者
export function addVisitor(dashboardId, username) {
  return request({
    url: `/api/dashboard-permission/${dashboardId}/visitor`,
    method: 'get',
    params: { username }
  })
}

// 移除访问者
export function removeVisitor(dashboardId, username) {
  return request({
    url: `/api/dashboard-permission/${dashboardId}/visitor/${username}`,
    method: 'delete'
  })
}

// 转让所有权
export function transferOwner(dashboardId, username) {
  return request({
    url: `/api/dashboard-permission/${dashboardId}/owner`,
    method: 'put',
    data: username
  })
}

// 检查权限
export function checkPermission(dashboardId, userId) {
  return request({
    url: `/api/dashboard-permission/${dashboardId}/check`,
    method: 'get',
    params: { userId }
  })
} 